package cn.itcast.bos.web.action.transit;

import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.service.transit.TransitInfoService;
import cn.itcast.bos.web.action.common.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;


@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototyoe")
public class TransitInfoAction extends BaseAction<TransitInfo> {

    @Autowired
    private TransitInfoService transitInfoService;


    private String wayBillIds;

    public void setWayBillIds(String wayBillIds) {
        this.wayBillIds = wayBillIds;
    }

    //transit_create.action运输配送信息实例
    @Action(value = "transit_create",results = {@Result(name = "success",type = "json")})
    public String create(){
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            transitInfoService.createTransits(wayBillIds);
            // 成功
            result.put("success", true);
            result.put("msg", "开启中转配送成功");
        } catch (Exception e) {
            e.printStackTrace();
            // 失败
            result.put("success", false);
            result.put("msg", "开启中转配送失败，异常：" + e.getMessage());
        }
        ActionContext.getContext().getValueStack().push(result);
        return SUCCESS;
    }



}
